package com.subtlman.logframework.resp;

import com.fasterxml.jackson.annotation.JsonIgnore;
import jdk.nashorn.internal.ir.annotations.Ignore;

import java.util.List;
import java.util.Map;

/**
 * @Create: IntelliJ IDEA.
 * @Author: subtlman_ljx
 * @Date: 2022/11/12/0:20
 * @Description: Detailed Inform
 */
public final class InformResp implements java.io.Serializable{

    // 请求路径
    @JsonIgnore
    private String requestPath;
    // 请求方法
    @JsonIgnore
    private String requestMethod;
    // 当前的时间戳
    @JsonIgnore
    private Long currentTimeMills;
    // 参数类型
    @JsonIgnore
    private Map<String, String> argsType;
    // 所有入参
    @JsonIgnore
    private List<Object> allArgs;
    // 响应数据
    @JsonIgnore
    private String responseData;
    // 当前执行耗时
    @JsonIgnore
    private String executeTimeMills;
    // 当前请求的方法路径：（类路径 + 方法名字）
    @JsonIgnore
    private String classMethodLocation;
    // 请求的IP
    @JsonIgnore
    private String remoteAddr;
    // 当前日期（yyyy-MM-dd HH:mm:ss）
    @JsonIgnore
    private String nowTime;
    // 响应数据类型
    @JsonIgnore
    private String responseType;
    // 是否有异常
    public boolean excepStatus;
    // 异常信息
    public ExcepInform excepInform;

    public InformResp(){}

    public static InformResp getInstance(){
        return new InformResp();
    }

    public InformResp(String requestURI, String requestMethod, Long startTime, Map<String, String> methodArgumentTypeName, List<Object> args, String s, String s1, String s2, String remoteAddr, String format, String name) {
        this.requestPath=requestURI;
        this.requestMethod=requestMethod;
        this.currentTimeMills=startTime;
        this.argsType=methodArgumentTypeName;
        this.allArgs=args;
        this.responseData=s;
        this.executeTimeMills=s1;
        this.classMethodLocation=s2;
        this.remoteAddr=remoteAddr;
        this.nowTime=format;
        this.responseType=name;
    }

    @Override
    public String toString() {
        return "InformResp{" +
                "requestPath='" + requestPath + '\'' +
                ", requestMethod='" + requestMethod + '\'' +
                ", currentTimeMills=" + currentTimeMills +
                ", argsType=" + argsType +
                ", allArgs=" + allArgs +
                ", responseData='" + responseData + '\'' +
                ", executeTimeMills='" + executeTimeMills + '\'' +
                ", classMethodLocation='" + classMethodLocation + '\'' +
                ", remoteAddr='" + remoteAddr + '\'' +
                ", nowTime='" + nowTime + '\'' +
                ", responseType='" + responseType + '\'' +
                ", excepStatus=" + excepStatus +
                ", excepInform=" + excepInform +
                '}';
    }

    public String getRequestPath() {
        return requestPath;
    }

    public void setRequestPath(String requestPath) {
        this.requestPath = requestPath;
    }

    public String getRequestMethod() {
        return requestMethod;
    }

    public void setRequestMethod(String requestMethod) {
        this.requestMethod = requestMethod;
    }

    public Long getCurrentTimeMills() {
        return currentTimeMills;
    }

    public void setCurrentTimeMills(Long currentTimeMills) {
        this.currentTimeMills = currentTimeMills;
    }

    public Map<String, String> getArgsType() {
        return argsType;
    }

    public void setArgsType(Map<String, String> argsType) {
        this.argsType = argsType;
    }

    public List<Object> getAllArgs() {
        return allArgs;
    }

    public void setAllArgs(List<Object> allArgs) {
        this.allArgs = allArgs;
    }

    public String getResponseData() {
        return responseData;
    }

    public void setResponseData(String responseData) {
        this.responseData = responseData;
    }

    public String getExecuteTimeMills() {
        return executeTimeMills;
    }

    public void setExecuteTimeMills(String executeTimeMills) {
        this.executeTimeMills = executeTimeMills;
    }

    public String getClassMethodLocation() {
        return classMethodLocation;
    }

    public void setClassMethodLocation(String classMethodLocation) {
        this.classMethodLocation = classMethodLocation;
    }

    public String getRemoteAddr() {
        return remoteAddr;
    }

    public void setRemoteAddr(String remoteAddr) {
        this.remoteAddr = remoteAddr;
    }

    public String getNowTime() {
        return nowTime;
    }

    public void setNowTime(String nowTime) {
        this.nowTime = nowTime;
    }

    public String getResponseType() {
        return responseType;
    }

    public void setResponseType(String responseType) {
        this.responseType = responseType;
    }

    public boolean isExcepStatus() {
        return excepStatus;
    }

    public void setExcepStatus(boolean excepStatus) {
        this.excepStatus = excepStatus;
    }

    public ExcepInform getExcepInform() {
        return excepInform;
    }

    public void setExcepInform(ExcepInform excepInform) {
        this.excepInform = excepInform;
    }

    public InformResp success(){
        InformResp resp = InformResp.getInstance();
        resp.setExcepStatus(false);
        resp.setExcepInform(null);
        return resp;
    }

    public InformResp error(Exception e){
        InformResp resp = InformResp.getInstance();
        resp.setExcepStatus(true);
        resp.setExcepInform(ExcepInform.getInstance().formatException(e));
        return resp;
    }
}
